Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move Weather page to the Blazor Web Client project when using WebAssembly-based interactivity #55877

Closed
wants to merge 3 commits into from

Conversation

mkArtakMSFT
Copy link
Member

Addresses #55307

@mkArtakMSFT mkArtakMSFT added the area-blazor Includes: Blazor, Razor Components label May 25, 2024
@mkArtakMSFT mkArtakMSFT marked this pull request as ready for review June 4, 2024 20:39
* Don't generate the weather forecast API when either:
  * Auto mode is used
  * We're generating an empty template
* Removed extra whitespace
* Reorganized/refactored the weather forecast model and service
* Fixed issues with weather forecast files being included when they shouldn't be
@MackinnonBuck
Copy link
Member

This PR currently updates the templates so that when WebAssembly is the only enabled interactive render mode, the Weather page uses WebAssembly interactivity with prerendering disabled. The interactive version of the Weather page makes an HTTP request to fetch weather forecast data upon component initialization.

This has some limitations:

  • There's a period where content on the Weather page is "blank", and this period is particularly long if the Weather page is the first interactive page navigated to. This is expected as a natural consequence of disabling prerendering, but it doesn't look good (especially since there's no loading text, since that's also rendered interactively).
    • This is even worse with top-level interactivity, because then you just get a blank screen while WebAssembly initializes. We could address this by re-introducing the loading indicator when top-level interactivity is used with WebAssembly.
  • It doesn't demonstrate how to solve the problem when using the Auto render mode.

We could alternatively:

  • Introduce an IWeatherForecast interface with implementations on the server and the client
  • Inject that service into the existing Weather page
  • If WebAssembly interactivity is enabled, place the Weather page in the client project
  • If any interactivity option is enabled, add a check to make sure we're interactive before fetching data (to avoid the double-fetching issue):
    if (RendererInfo.IsInteractive)
    {
      forecasts = weatherForecast.GetWeatherForecastAsync();
    }

While it solves the issues I described above, it does introduce a tad bit more complexity into the template. However, it's closer to what I believe we'd recommend for a real, production-quality app.

An even better long term solution would be to utilize #51584 when it gets implemented, but that may happen after the template changes for .NET 9 have been locked down.

Thoughts?

@MackinnonBuck
Copy link
Member

cc @dotnet/aspnet-blazor-eng

@dotnet-policy-service dotnet-policy-service bot added the pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun label Jun 15, 2024
@dotnet-policy-service dotnet-policy-service bot added this to the 10.0-preview1 milestone Nov 12, 2024
@mkArtakMSFT mkArtakMSFT deleted the mkArtakMSFT/httpClient branch November 12, 2024 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-blazor Includes: Blazor, Razor Components pending-ci-rerun When assigned to a PR indicates that the CI checks should be rerun
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants